<?php

class ManagementController extends BackendController
{
    public function actionIndex()
    {
        Yii::import('application/modules/user/models/User');
        $user=new User();

        $criteria=new CDbCriteria();
        //$criteria->with=array('statistics');

        if(isset($_GET['ajax']) && isset($_GET['User'])){
            if($_GET['User']['isActive']!=1) $_GET['User']['isActive']=0;
            $user->attributes=$_GET['User'];
        }

        if($user->role===0) $user->role='';
        if($user->isActive===0) $user->isActive='';

        $criteria->compare('id',$user->id,true);
        $criteria->compare('userName',$user->userName,true);
        $criteria->compare('password',$user->password,true);
        $criteria->compare('email',$user->email,true);
        $criteria->compare('role',$user->role,true);
        $criteria->compare('isActive',$user->isActive,true);
        $criteria->compare('lastLoginTime',$user->lastLoginTime,true);
        //$criteria->compare('dateVisit',$user->dateVisit,true);
        $criteria->compare('dateRegistered',$user->dateRegistered,true);


        $dataProvider=new CActiveDataProvider($user, array(
            'criteria' =>$criteria,
            'sort'=>array(
                'attributes'=>array(
                    'dateVisit'=>array(
                        'asc'=>'statistics.dateVisit',
                        'desc'=>'statistics.dateVisit desc',
                    ),
                    '*',
                ),
            ),
            'pagination'=>array(
                'pageSize'=>Yii::app()->params['adminElementsPerPage'],
            ),
        ));

        $this->categoryImage=(object)array(
            'img'=>Yii::app()->theme->baseUrl.'/images/Crystal_Clear_users.gif',
        );

        $this->render('index',array(
            'dataProvider'=>$dataProvider,
            'user'=>$user,
            'action'=>$this->createUrl('user/user'),
        ));
    }
}